<template>
  <a-modal
    title="新增系统信息表"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          label="系统名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入系统名称" v-decorator="['sysname', {rules: [{required: true, message: '请输入系统名称！'}]}]" />
        </a-form-item>
        <a-form-item
          label="系统编号"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入系统编号" v-decorator="['sysid', {rules: [{required: true, message: '请输入系统编号！'}]}]" />
        </a-form-item>
        <a-form-item
          label="渠道编号"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入渠道编号" v-decorator="['channel', {rules: [{required: true, message: '请输入渠道编号！'}]}]" />
        </a-form-item>
        <a-form-item
          label="系统介绍"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-textarea placeholder="请输入系统介绍" v-decorator="['detail', {rules: [{required: true, message: '请输入系统介绍！'}]}]" :auto-size="{ minRows: 3, maxRows: 6 }"/>
        </a-form-item>
        <a-form-item
          label="系统提供商"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入系统提供商" v-decorator="['provider', {rules: [{required: true, message: '请输入系统提供商！'}]}]" />
        </a-form-item>
        <a-form-item
          label="目前阶段"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入目前阶段" v-decorator="['stage', {rules: [{required: true, message: '请输入目前阶段！'}]}]" />
        </a-form-item>
        <a-form-item
          label="上线日期"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入上线日期" v-decorator="['update', {rules: [{required: true, message: '请输入上线日期！'}]}]" />
        </a-form-item>
        <a-form-item
          label="运维人员"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入运维人员" v-decorator="['worker']" />
        </a-form-item>
        <a-form-item
          label="研发支持人员"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入研发支持人员" v-decorator="['rdcWorker']" />
        </a-form-item>
        <a-form-item
          label="运营部门"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入运营部门" v-decorator="['dept', {rules: [{required: true, message: '请输入运营部门！'}]}]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { xjbSysdetailAdd } from '@/api/modular/main/xjbsysdetail/xjbSysdetailManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object' && values[key] != null) {
                values[key] = JSON.stringify(values[key])
              }
            }
            xjbSysdetailAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败')// + res.message
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
